package com.rimi.live.service;

import com.rimi.live.bean.Role;
import com.rimi.live.bean.RoleExample;
import com.rimi.live.mapper.RoleMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoleServer extends CommonServer {
    @Resource
    private RoleMapper roleMapper;

    {
        listUrl = "/role/index";
    }

    public void insertRole(Role role) {
        RoleExample roleExample = new RoleExample();
        roleExample.createCriteria().andNameEqualTo(role.getName());
        List<Role> roles = roleMapper.selectByExample(roleExample);
        if (!roles.isEmpty()) {
            setErrorMsg("角色名称已存在");
            return;
        }
        int back = roleMapper.insert(role);
        if (back > 0) {
            setSuccessMsg("添加成功！");
        } else {
            setErrorMsg("添加失败！");
        }
    }

    public List<Role> getAllRole(){
        List<Role> roles = roleMapper.selectByExample(null);
        return roles;
    }

}
